<template>
	<div class="order_list_div">

		<!--头部-->
		<!-- 原版 -->
		<div style="position: fixed;width: 100%;z-index:999;background:#fff;">
			<header class="customHeaderStyle" style="position: relative;top: 0">
				<router-link to="profile">
					<div class="go-back">
						<i></i>
						<i></i>
						<i></i>
					</div>
				</router-link>
				<keep-alive>
					<div class="headerCustomTitle">
						{{number == 0 ? "全部订单" : (number == 1 ? "未付款订单" : (number == 2 ? "待配送订单" : (number == 3 ? "配送中订单" : (number == 4 ? "待评价订单" : '' )))) }}
					</div>
				</keep-alive>
			</header>
			<TapHead v-if="headList" :titleInfor="headList">
            
			</TapHead>

		</div>
		<!-- 原版 -->
		<!--头部-->

		<!-- <QXZHeader :hasBack="true" :hasTitle="true">
        <keep-alive>
          <div class="aui-title">
            {{number == 0 ? "全部订单" : (number == 1 ? "未付款订单" : (number == 2 ? "待配送订单" : (number == 3 ? "配送中订单" : (number == 4 ? "待评价订单" : '' )))) }}
          </div>
        </keep-alive>
      </QXZHeader>
      <TapHead v-if="headList" :titleInfor="headList">

      </TapHead>

      <div style="position:absolute; width: 100% ; height: 0;bottom:0;z-index: 10">
        <animate-refresh @dataRefresh="dataRefresh" ref="animatexl">
        </animate-refresh>
      </div> -->

		<!--订单tab滚动切换模块-->
		<!--商品列表-->
		<translate-group :name="animateClassName" ref="TranslateGroup" @scrollBottom="scrollBottom" :lengths="5" style='padding-top:5rem'>
			<div class="centent">
				<div v-if="showBgImage" class="no_data" slot="other">
					<img src="static/image/no_order.png" height="280" width="380" />
					<p>订单里没有东西哦，快去挑选吧~</p>
					<div class="back_home aui-btn aui-btn-outlined" @click.stop="goHome">逛逛首页</div>
				</div>

				<ul class="aui-list aui-media-list commodity_list subtotal_list" v-for="(item, index) in data" :key="index" style="position: static;">
					<li class="aui-list-item">
						<router-link :to="item.orderType === 3 ? {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number,}}: 
						(item.orderType === 4? {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number }}: { path: 'orderDetails', query: { shopId: item.parentOrderNo, orderStatus: number ,hasInvoice:item.hasInvoice ,canInvoiceType:item.canInvoice,status:orderTypeStatus(item)}})">
							<div class="aui-list-item-inner">
								<div class="aui-list-item-text">
									<div class="aui-list-item-title">单号：{{item.orderNo}}</div>

									<div class="aui-list-item-right" v-if="item.scanOrder === 1">
										<span class="aui-text-danger">{{orderTypeStatus(item)}}</span>
									</div>
									<div class="aui-list-item-right" v-else-if="(item.orderType === 1 || item.orderType === 5 || item.orderType === 6) && item.scanOrder !== 1">
										<span class="aui-text-danger">{{orderTypeStatus(item)}}</span>
									</div>
									<div class="aui-list-item-right" v-else-if="item.orderType === 2">
										<span class="aui-text-danger">{{orderTypeStatus(item)}}</span>
									</div>
									<div class="aui-list-item-right" v-else-if="item.orderType === 3"><!-- 线上堂食订单-->
										<span class="aui-text-danger">{{tangshiStatus(item)}}</span>
									</div>
									<div class="aui-list-item-right" v-else-if="item.orderType === 4"><!-- 线下堂食订单-->
										<span class="aui-text-danger">{{offlineStatus(item)}}</span>
									</div>
									<div class="aui-list-item-right" v-else>
										<span class="aui-text-danger">{{orderTypeStatusing(item)}}</span>
									</div>
								</div>
								<!--<div class="aui-list-item-text">
                                <div class="aui-list-item-title">{{item.orderNo}}</div>
                            </div>-->
								<div class="aui-list-item-text">
									{{item.createTm | getTime}}
									<div v-html="orderType(item)" style="float:right;"></div>
								</div>
							</div>
						</router-link>
					</li>
					<li class="aui-list-item" v-for="(son, num) in item.orderDetails" :key="num">
						<router-link :to="item.orderType === 3 ? {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number, status:statusTs(item),}}: 
						(item.orderType === 4? {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number ,status:statusTs(item),}}: 
						{ path: 'orderDetails', query: { shopId: item.parentOrderNo, orderStatus: number ,hasInvoice:item.hasInvoice ,status:orderTypeStatus(item)}})">
							<!--@touchstart.stop="turnPage(item,1)"-->
							<div class="aui-media-list-item-inner">
								<div class="aui-list-item-media">
									<span class="img_span" :class="son.buyType == 3 ? 'img_span_1' : ''">{{(son.buyType == 2 ? "加价购" : (son.buyType == 3 ? "赠品" : ""))}}</span>
									<img :src="son.goodsImg || 'static/image/demo2.png'">
								</div>
								<div class="aui-list-item-inner suggest" style="text-align:left;">
									<h3>{{son.goodsName}}</h3>
									<p>{{son.goodsSpec || ''}}</p>
									<p v-if="son.activityFlag == true && item.orderType!=2">¥{{realPrice(item,son)}}
										<!-- &nbsp;<del>¥{{sonPrice(item,son)}}</del> -->
										 {{son.goodsUnit ? '/' : ''}}&nbsp;{{son.goodsType == 2 ? son.mallUnit : (son.goodsUnit == 'kg' ? '500g' : (son.mallUnit || ''))}}
									</p>
									<p v-if="(son.activityFlag == false && item.orderType!=2)|| item.orderType==2">¥{{sonPrice(item,son)}}{{son.goodsUnit?'/':''}}&nbsp;{{son.goodsType == 2 ? son.mallUnit : (son.goodsUnit == 'kg' ? '500g' : (son.mallUnit || ''))}}</p>
									<p v-if="son.workingInfo && son.workingInfo != '[]'">
										加工服务：<span style="color:#1E1E1E">{{getworkingInfo(JSON.parse(son.workingInfo))}}</span>
									</p>
								</div>
								<div class="subtotal">
									<span v-if="son.activityFlag == true && item.orderType!=2">¥{{Number(son.realTotalMoney).toFixed(2) }}<del style="color:#6b6b6b;"><br/>¥{{Number(son.totalMoney).toFixed(2) }}</del></span>
									<span v-if="son.activityFlag == false && item.orderType!=2">¥{{Number(son.totalMoney) == 0 ?  '0.00' : Number(son.totalMoney).toFixed(2) }}</span>
									<span v-if="item.orderType==2">{{son.realPrice+'积分'}}{{son.goodsUnit?'/':''}}&nbsp;{{son.goodsUnit == 'kg' ? '500g' :(son.goodsUnit || '')}}</span>
									<!--<p v-if="item.orderType != 1"><em v-if="son.goodsType  != 7">x</em>{{son.goodsType === 7 ? son.outGoodsNum + 'kg' : son.outGoodsNum}}</p>
                  <p v-if="item.orderType == 1"><em v-if="son.goodsType  != 7 && son.goodsType  != 6">x</em>{{son.goodsType === 7 || son.goodsType === 6? son.actualWeight
                    + 'kg' : son.outGoodsNum}}</p>-->
									<p v-if="son.goodsType == 6"><em>x</em>{{son.goodsNum == 0 ? son.actualWeight + son.goodsUnit : son.goodsNum + (son.actualWeight ? '(' + son.actualWeight*1000 + 'g' +')' : '') }}</p>
									<p v-if="son.goodsType == 7"><em>x</em>{{son.actualWeight*1000 + 'g'}}</p>
								</div>

							</div>
						</router-link>
						<!--<div class="edit_address" v-show="Number(son.afterSaleStatus) == 0 && commentShow && item.logisticsStatus === 2 && !son.goodsCommentsFlag && item.orderType != 1">-->
						<!-- <div class="edit_address" v-show="commentShow && item.logisticsStatus === 2 && son.estimateStatus == 0 && item.orderType != 1 && item.orderType != 5 && item.status != 2 && item.orderType != 2">
							<div class="aui-btn aui-btn-danger aui-btn-outlined" @click.stop="goEvaluate(item, son)">去评价
							</div>
						</div>
						<div class="hasEvaluate" v-show="item.logisticsStatus === 2 && son.estimateStatus == 1 && item.orderType != 1 && item.orderType != 5 && item.orderType != 2">
							<div class="hasEvaluate_btn aui-btn aui-btn-outlined">已评价</div>
						</div> -->
					</li>
					<li class="aui-list-item">
						<div class="total_text">
							共{{add(item.orderDetails)}}件商品，共计：
							<span v-if="item.orderType!=2">¥{{Number(item.realPay).toFixed(2)}}</span>
							<span v-if="item.orderType==2">{{item.realPay}}积分</span>
							<span v-if="item.orderType !== 1 && item.orderType != 5 && item.orderType != 6 && item.scanOrder !== 1 && item.orderType !== 3">(邮费：¥{{Number(item.freight).toFixed(2)}})</span></div>
					</li>																						 
					<li class="edit_address">
						<!--<router-link id="aLink"
                                     :to="{ path: '/main/aftersalelist', query: { 'activeIndex': 1, orderSubNo: item.orderNo}}"
                                     v-show="item.status === 2 || item.status === 4">
                          {{item.status === 2 ? '部分退款' : (item.status === 4 ? '部分退货退款' : '')}}
                        </router-link>-->
						<div class="aui-btn aui-btn-danger aui-btn-outlined" v-show="item.logisticsStatus === 2  && item.status != 2 && item.orderType === 0 && !item.estimateFlag" @click.stop="goEvaluate(item.orderDetails)">去评价
						</div>	
						<div class="aui-btn aui-btn-outlined" v-show="item.payStatus === 0 && item.status !== 1 && !orderTypes(item.orderNo) && isApp && item.orderType !== 1 && item.orderType != 5 && item.orderType != 6 && item.scanOrder !==1">
							<pfoCom :orderNo="item.parentOrderNo">找人代付</pfoCom>
						</div>
						<div class="aui-btn aui-btn-outlined" v-show="item.payStatus === 0 && item.status !== 1 && !orderTypes(item.orderNo)" @click="cancelOrderAction(item.orderNo,item.parentOrderNo)">
							取消订单
						</div>
						<!-- 线下堂食订单的查看订单  如果是线下到线上  则隐藏查看   如果纯线下  则显示 -->
						<router-link :to=" {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number,status:statusTs(item),}}" v-if ="item.orderType === 4 && orderTypes(item.orderNo)">
							<div class="aui-btn aui-btn-outlined" >
								查看订单
							</div>
						</router-link>
						<!-- 线下堂食订单的查看订单  如果是线下到线上  则隐藏查看   如果纯线下  则显示 -->
						<router-link :to=" {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number ,status:statusTs(item),}}" v-if ="item.orderType === 4 && !orderTypes(item.orderNo)">
							<div class="aui-btn aui-btn-outlined" v-show="offlineStatus(item) != '待付款' ">
								查看订单
							</div>
						</router-link>
						<!-- 线上堂食订单的查看订单 -->
						<router-link :to=" {name:'churchOrderDetail',query:{ shopId: item.parentOrderNo, orderStatus: number, status:statusTs(item),}}" v-if="item.orderType === 3 && number != 1 &&  tangshiStatus(item) != '待付款' ">
							<div class="aui-btn aui-btn-outlined">
								查看订单
							</div>
						</router-link>
						
						
						<router-link v-if="item.orderType != 3 && item.orderType != 4 " :to="{ path: 'orderDetails', query: { shopId: item.parentOrderNo, orderStatus: number,hasInvoice:item.hasInvoice,status:orderTypeStatus(item) }}">
							<div class="aui-btn aui-btn-outlined" v-if="item.orderType === 1 || item.orderType === 5 || item.orderType === 6|| item.scanOrder === 1 ">
								查看订单
							</div>
							<div class="aui-btn aui-btn-outlined" v-show="(item.payStatus === 1 || item.payStatus === 2 || item.payStatus === 3 || item.logisticsStatus === 1 || item.status === 1)" v-else>
								查看订单
							</div>
						</router-link>
				
						<router-link v-if="(item.orderType==3 || item.orderType==4) " :to="{ path: 'BillParticulars', query: { ParentOrderNo: item.parentOrderNo, orderNo: item.orderNo ,creTime: item.createTm,storeOrderNo:item.storeOrderNo,orderStatus: number,}}">
							<div class="aui-btn aui-btn-outlined" v-if="statusTs(item)&& item.orderType != 2&&item.hasInvoice == 1 &&item.payType!=9&&item.payType!=6&&getInvoiceFlag==1&&item.status===0">
							<!-- <div class="aui-btn aui-btn-outlined" v-if="item.orderType!=3&&item.orderType!=4&& (orderTypeStatus(item)=='已完成'||orderTypeStatus(item)=='待评价')&&item.hasInvoice == 1 &&item.payType!=9&&item.payType!=6&&getInvoiceFlag==1"> -->
								查看发票
							</div>
						</router-link>
						<router-link v-else :to="{ path: 'BillParticulars', query: { ParentOrderNo: item.parentOrderNo, orderNo: item.orderNo ,creTime: item.createTm,storeOrderNo:item.storeOrderNo,orderStatus: number,}}">
							<div class="aui-btn aui-btn-outlined" v-if="(orderTypeStatus(item)=='已完成'||orderTypeStatus(item)=='待评价')&& item.orderType != 2&&item.hasInvoice == 1 &&item.payType!=9&&item.payType!=6&&getInvoiceFlag==1&&item.status===0">
							<!-- <div class="aui-btn aui-btn-outlined" v-if="item.orderType!=3&&item.orderType!=4&& (orderTypeStatus(item)=='已完成'||orderTypeStatus(item)=='待评价')&&item.hasInvoice == 1 &&item.payType!=9&&item.payType!=6&&getInvoiceFlag==1"> -->
								查看发票
							</div>
						</router-link>
						<router-link v-if="(item.orderType==3 || item.orderType==4) "  :to="{ path: 'BillDetail', query: { shopId: item.parentOrderNo, datas: item.orderNo , parentOrderNo: item.parentOrderNo,orderStatus: number,}}">
							<div class="aui-btn aui-btn-outlined" v-if=" item.orderType != 2 && statusTs(item)&& judgeTime(item) && item.status==0 && item.hasInvoice == 0 && item.payType!=9 && item.payType!=6 && getInvoiceFlag==1 && number == 0">
							<!-- <div class="aui-btn aui-btn-outlined" v-if="item.orderType!=3&&item.orderType!=4&& item.status==0 && item.hasInvoice == 0 && item.canInvoice && item.payType!=9&&item.payType!=6&&getInvoiceFlag==1"> -->
								开票申请
							</div>
						</router-link>	
						
						<router-link v-else :to="{ path: 'BillDetail', query: { shopId: item.parentOrderNo, datas: item.orderNo , parentOrderNo: item.parentOrderNo,orderStatus: number,}}">
							<div class="aui-btn aui-btn-outlined" v-if=" (orderTypeStatus(item)=='已完成'||orderTypeStatus(item)=='待评价')&& item.status==0 && item.orderType != 2 && item.hasInvoice == 0 && judgeTime(item) && item.payType!=9&&item.payType!=6&&getInvoiceFlag==1">
							<!-- <div class="aui-btn aui-btn-outlined" v-if="item.orderType!=3&&item.orderType!=4&& item.status==0 && item.hasInvoice == 0 && item.canInvoice && item.payType!=9&&item.payType!=6&&getInvoiceFlag==1"> -->
								开票申请
							</div>
						</router-link>	

						<!-- <router-link :to="{name: 'pay',params:{orderNo:item.parentOrderNo,orderType:item.orderType}}"> -->
						<div id="order_payment" class="aui-btn aui-btn-danger aui-btn-outlined" v-show="item.payStatus === 0 && item.status !== 1 && !orderTypes(item.orderNo)" @click="confirmPay(item.orderNo,item.parentOrderNo, handleOrderType(item.orderType))">马上支付
						</div>
						<!-- "item.payStatus === 0 && item.status !== 1 && !orderTypes(item.orderNo)"  -->
						<!-- </router-link> -->
						<!-- <router-link :to="{name:'logistics',params:{imgurl: img(item.orderDetails),orderNo:item.orderNo}}">
                        <div id="" class="aui-btn aui-btn-danger aui-btn-outlined" v-show="item.logisticsStatus === 1">查看物流
                        </div> -->
						<!--</router-link>-->
						<!--<div id="" class="aui-btn aui-btn-danger aui-btn-outlined"-->
						<!--v-show="item.logisticsStatus === 1" @click="confirm(item.orderNo)">确认收货-->
						<!--</div>-->

					</li>
				</ul>

			</div>
			<div v-if="isShowLoadMore" style="margin-top: 20px;color:#444444 ;height:2rem!important;  width: 100%;text-align: center;  line-height: 2rem;vertical-align: middle ; background:white;font-weight: 600" @click.self="changeFloat">
				<LoadMoreAnimate></LoadMoreAnimate>
				正在加载...
			</div>
		</translate-group>

		<!--商品列表 end-->
		<!--订单页是空的-->

		<!--订单页是空的 end-->

	</div>
</template>

<script>
	import { getAllOrder, cancelOrder, confirmOrder, selectCommentConfig, confirmPayment } from "../../api/wxh/getData.js"
	import { mapGetters, mapMutations, mapActions } from "vuex"
	import { TabContainer, TabContainerItem, Loadmore } from 'mint-ui'
	import { MessageBox } from "../../ui-components"
	import { Toast } from '../../utils/toast.js'
	import RepairHead from "../repairHead"
	import TranslateGroup from '../../real-components/TranslateTest'
	import AnimateRefresh from "../../real-components/AnimateRefresh";
	import TapHead from '../../real-components/TabHeadOrder';
	import LoadMoreAnimate from '@/real-components/LoadMoreAnimate';
	import QXZHeader from '@/real-containers/header';
	import pfoCom from '../../real-components/payForOthers/pfo.vue'
	import {normal,tangshi,saomagou,xianxia} from "../../config/orderTypeCode";
	import {showLoading, hideLoading} from '../../utils/loading.js'
	import axios from "axios";

	export default {
		data() {
			return {
				data: [],
				newArr: [],
				isiOS: null,
				isAndroid: null,
				order: [],
				list: ['全部', '待付款', '待配送', '配送中', '已签收'],
				headList: [{
					goodsClassNum: "",
					goodsClassName: '全部'
				}, {
					goodsClassNum: "",
					goodsClassName: '待付款'
				}, {
					goodsClassNum: "",
					goodsClassName: '待配送'
				}, {
					goodsClassNum: "",
					goodsClassName: '配送中'
				}, {
					goodsClassNum: "",
					goodsClassName: '待评价'
				}],
				activeIndex: 0,
				range: null,
				move: true,
				animateClassName: "slide-left",
				number: null, //从profile 入口
				title: null,
				numberTurn: null, //订单内部切换
				timeInterval_1: '',
				commentShow: false, //展示评论
				showBgImage: false,
				price: '',
				pageNum: 1, //分页
				totalPageCount: '',
				topDropText: "",
				bottomLoadingText: "",
				// orderTypes: "",
				isShowLoadMore: false,
				flag_pullrefresh: false,
				timeSettime:'',
				
			}
		},
		beforeDestroy() {
			this.data = [];
			this.newArr = [];
			this.hideLoading();
			clearTimeout(this.timeSettime);
		},
		async mounted() {
			await this.getUserInfo();
			await this.initData();
			// this.getOrder();
			this.number = this.$route.query.orderStatus || 0;
			this.status();
			this.$store.dispatch('cjy/changeClassifyIndex', this.number);
			this.$store.dispatch('hzh/setAMarks', true);
			this.getNum(this.$store.state.cjy.classifyIndex);
			this.getBillStatus();
		},
		components: {
			RepairHead,
			TranslateGroup,
			AnimateRefresh,
			TapHead,
			'mt-loadmore': Loadmore,
			LoadMoreAnimate,
			QXZHeader,
			"pfoCom": pfoCom,
			// Loadmore.name
		},
		computed: {
			...mapGetters('wxh', [
				'sessionId',
				'login',
				'userInfo'
			]),
			...mapGetters('zwy', [
				'getInvoiceFlag',
			]),
			num() {
				this.pageNum = 1;
				this.data = [];
				this.newArr = [];
				return this.$store.state.cjy.classifyIndex;
			},
			isApp() {
				return false;
				// return window.cordova ? true : false
			}
		},
		watch: {
			num(newdd, olddd) {
				if(newdd - olddd > 0) {
					this.animateClassName = "slide-right"
				} else {
					this.animateClassName = "slide-left"
				}
				this.number = this.$store.state.cjy.classifyIndex;
				console.log('number', this.number);
				this.status();
				this.getNum()
			}

		},
		methods: {
			...mapMutations('zwy',[
				'setInvoiceFlag',
			]),
			//根据是否已取餐来判断可否申请开发票
			//判断方法当前时间减去confirmTm时间是否大于三个月
			judgeTime(item){
				let times = item.confirmTm?item.confirmTm:item.payTm
				var timestamp2 =(new Date()).valueOf();
				let timestamp =  timestamp2 - times;
				let taltimestamp = Number((((timestamp/1000)/60)/60)/24);
				console.log("taltimestamp",taltimestamp)
				if(times && taltimestamp > 90 && item.hasInvoice === 0){
					// console.log("osahfasfhashfaosf..................")
					return false
				}else if(times == null){
					// console.log("132131313131313131..................")
					return false
				}else{
					// console.log("132131313131313131..................")
					return true
				}
			},
			//匹配堂食发票的状态
			statusTs(item){
				let num = 0
				if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum == 0 &&item.eatingStatusNumber.completedNum >0){
					num= 1;
				}
				return num
			},
			orderType(item) {
				if (item.scanOrder === 1) {
					return '<span  style="color:#666666;">扫码购订单</span>'
				} else if (item.orderType === 1 && item.scanOrder !== 1) {
					return '<span  style="color:#666666;">门店订单</span>'
				} else if (item.orderType === 2) {
					return '<span  style="color:#666666;">积分订单</span>'
				} else if (item.orderType === 3) {
					return '<span style="color:#666666;">线上堂食订单</span>'
				} else if (item.orderType === 4) {
					return '<span style="color:#666666;">线下堂食订单</span>'
				}  else if (item.orderType === 5) {
					return '<span style="color:#666666;">线下自助收银订单</span>'
				} else if (item.orderType === 6) {
					return '<span style="color:#666666;">线下称重加工订单</span>'
				}
			},
			...mapActions('wxh', [
				'getUserInfo'
			]),
			...mapMutations('wxh', [
				'USER_INFO',
				'LOGO_OUT',
				'LOGO_IN'
			]),
			/**
			 * 处理订单类型，给到支付页面
			 * orderType：后台返回的订单类型
			 * 线上订单=》 0:线上，3：线上堂食订单，2：积分订单
			 * 线下订单=》 1:新下pos收银订单，4：线下堂食订单，5：线下自助收银订单， 6：线下称重加工订单，7：线下扫码购订单
			 */
			handleOrderType(orderType) {
				// normal,tangshi,saomagou,xianxia
				orderType = Number(orderType);
				if(orderType === 0 || orderType === 2){
					return normal
				}else if(orderType=== 3 || orderType=== 4){
					return tangshi
				}else if(orderType=== 7){
					return saomagou
				}
			},
			// //处理订单类型，给到支付页面
			// handleOrderType(orderType) {
			// 	//如果不是APP下单，返回normal
			// 	if(orderType === 1 || orderType === 5 || orderType === 6 ) {
			// 		return normal;
			// 	} else if (orderType === 3) {
			// 		return tangshi;
			// 	} else if (orderType === 7){
			// 		return saomagou;
			// 	}
			// 	return orderType;
			// },
			//刷新页面
			refresh() {
				this.$nextTick(() => {
					this.$refs.TranslateGroup && this.$refs.TranslateGroup.refresh();
				});
			},
			//下拉加载数据
			scrollBottom() {
				if(this.totalPageCount > this.pageNum) {
					this.pageNum++;
					this.flag_pullrefresh = true;
					this.getNum();
				} else {
					this.topDropText = "已经到底部了！"
					return
				}

			},
			//上拉刷新
			dataRefresh() {
				this.$refs.animatexl.loadingOver();

				if(this.pageNum <= 1) {
					this.pageNum = 1;
					this.topDropText = "已经是最新了！"
					return
				} else {
					this.pageNum--;
				}
				this.flag_pullrefresh = true;
				this.getNum();
			},

			//去首页，逛逛首页
			goHome() {
				this.$router.push({
					path: "/"
				});
			},
			async initData() {
				if(!this.login) {
					this.username = '登录/注册';
					return
				}

				await this.reFreshUserInfo(this);

			},
			async getNum() {
				this.pageNum > 1 ? this.isShowLoadMore = true : this.showLoading();

				this.showBgImage = false;
				let u = navigator.userAgent;
				this.isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android
				this.isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
				if(!this.login) {
					MessageBox.confirm('请先登录！')
						.then(action => {
							this.$router.push({
								path: 'login',
								query: {
									page: 1
								}
							});
							return
						})
						.catch(error => {
							console.log(error);
						})
				}

				let config = {
					index: this.number,
					pageNum: this.pageNum,
					pageSize: 10,
				}
				let res = await getAllOrder(config);
				let i = 1;
				console.log(res,"9999999999999999999999999999999999999999999999999999",i++)
				if(res.status === 200) {
					if(res.data.returnCode === 1) {
						if(!res.data.data[0].results.length) {
							// Toast({
							//   message: "没有数据",
							//   duration: api.alertTime,
							//   type: 'fail'
							// });
							this.showBgImage = true;
							this.pageNum > 1 ? this.isShowLoadMore = false : this.hideLoading();
							return
						} else {
							this.showBgImage = false;
						}
					};
				} else {
					Toast({
						message: "网络错误",
						duration: api.alertTime,
						type: 'fail'
					});
					this.showBgImage = true;
					this.pageNum > 1 ? this.isShowLoadMore = false : this.hideLoading();
					return
				}
				this.totalPageCount = res.data.data[0].totalPageCount;
				this.newArr = [];

				if(this.$store.state.cjy.classifyIndex != 0 && this.$store.state.cjy.classifyIndex != 4) {
					for(let i of res.data.data[0].results) {
						if(i.status !== 3 && i.status !== 5) {

							this.newArr.push(i);
						}
					}
				} else if(this.$store.state.cjy.classifyIndex == 4) {
					for(let j of res.data.data[0].results) {
						if(j.status !== 3 && j.status !== 5 && j.orderType !== 2) {

							this.newArr.push(j);
						}
					}
				} else {
					this.newArr = res.data.data[0].results;
				}
				console.log('this.newArr', this.newArr);

				this.pageNum > 1 ? this.isShowLoadMore = false : this.hideLoading();
				//签收自动取消功能;
				let req = await selectCommentConfig();

				if(req.data[0].commentOn == 1) {
					this.commentShow = true;
					// console.log("this.data------------------------------//////////////////////////////////",this.data)
					// let T = new Date().getTime();
					// [...this.data].forEach((val) => {
					//   if (val.payStatus == 0 && val.autoCancelTm && val.status != 1) {
					//     if (val.autoCancelTm > T) {
					//       this.timeInterval_1 = setInterval(() => {
					//         if (val.autoCancelTm <= T) {
					//           this.cancelConfirm(val.orderNo);
					//         }
					//       }, 1000);
					//     }
					//     if (val.autoCancelTm <= T) {
					//       this.cancelConfirm(val.orderNo);
					//     }
					//   }

					// })
				}
				//门店订单只在全部tab展示，过滤;
				let newArr_1 = [];
				if(this.number != 0 && this.number !== 1) {
					[...this.newArr].forEach((val, index) => {
						//门店订单和扫码单同样处理
						if(val.orderType != 1 && val.orderType != 5  && val.orderType != 6 && val.scanOrder != 1) {
							newArr_1.push(val);
						}
					});

					this.flag_pullrefresh ? this.data = [...this.data, ...newArr_1] : this.data = newArr_1;

					this.pageNum > 1 ? !this.isShowLoadMore : this.isShowLoadMore;
					//this.flag_pullrefresh = false;
					return
				}
				this.flag_pullrefresh ? this.data = [...this.data, ...this.newArr] : this.data = this.newArr;
				// this.flag_pullrefresh = false;
				//未支付单的时候则开启定时器
				 console.log("4566666/////////////////////////////////////////////////",this.number)
				if(this.number === 1||this.number===0){
					 console.log("123/////////////////////////////////////////////////")
					this.detailTime(res, this.data)
				}
				
				console.log('this.data', this.data);
				if(!this.data.length) {
					this.showBgImage = true;
				} else {
					this.showBgImage = false;
				}

			},
			detailTime(res,datas){
				let systemTm = res.data.data[0].systemTm;
				let T = systemTm;
				
				[...this.data].forEach((val,lists) => {
					if (val.payStatus == 0 && val.autoCancelTm && val.status != 1 ) {
						// if (val.autoCancelTm > T) {
						// 	let second =parseInt((val.autoCancelTm - T) )
						// 	// this.timeSettime = setTimeout(() => {
						// 	// 	// this.cancelConfirms(val.orderNo,1);
						// 	// }, second);

						// }else{
						// 	// this.cancelConfirms(val.orderNo,1);
						// 	this.data.splice(lists, 1);
						// }
						let second =parseInt((val.autoCancelTm - T) )
						// let that = this;
						this.runTime(second,val.orderNo,lists);
					}
				})
			},
			async runTime(second,val,lists){
//				console.log("1234567890")
				if(second >0){
					this.timeSettime = setTimeout(() => {
						this.runTime(second -= 1000,val,lists)
//						 console.log("1234567890",second)
					}, 1000);
				}else{
					let ress = await cancelOrder(val);
					console.log(ress.returnCode,"aaaaaaaaaaaaa")
					if(ress.returnCode == 2) {
						console.log(ress.returnCode,"bbbbbbbbbbbbbbbbbbbbb")
						return false
					}else{
						console.log("99999999998888877777")
						if(this.data.length){
							this.data[lists].status = 1;
						}
					}
					clearTimeout(this.timeSettime);
					// this.timeSettime = null;
					//  that.data.splice(lists, 1);
					// that.data[lists].status = 1;
					// return
				}
				
			},
			status() {
				switch(this.number) {
					case 0:
						this.number = 0;
						this.title = "全部订单";
						break;
					case 1:
						this.number = 1;
						this.title = "未付款订单";
						break;
					case 2:
						this.number = 2;
						this.title = "待配送订单";
						break;
					case 3:
						this.number = 3;
						this.title = "配送中订单";
						break;
					case 4:
						this.number = 4;
						this.title = "待评价订单";
						break;
				}
			},
			async cancelOrderAction(val,parentOrderNo) {
				let res = await confirmPayment(parentOrderNo);
				if(res.returnCode == '0') {
					Toast({
						message: res.msg,
						duration: 2000,
						type: 'fail'
					});
					return;
				} else {
					let result = await MessageBox.confirm('确定执行此操作?');

					if(!result) return;
					this.cancelConfirm(val, 1);
				}
			},
			async cancelConfirm(val, param) {

				let res = await cancelOrder(val);
				if(param) {
					if(res.returnCode == 0) {
						Toast({
							message: res.msg,
							duration: 2000,
							type: 'fail'
						});
					}

					if(res.returnCode == 1 || res.returnCode == '1') {
						this.$store.commit('xxy/setPay', false)
						Toast({
							message: "订单取消成功",
							duration: 2000,
							type: 'success'
						});
					}
					this.pageNum = 1;
					this.data = [];
					this.getNum();
				}
			},
			async cancelConfirms(val, param) {

				let res = await cancelOrder(val);
				if(param) {
					if(res.returnCode == 0) {
						Toast({
							message: res.msg,
							duration: 2000,
							type: 'fail'
						});
					}

					if(res.returnCode == 1 || res.returnCode == '1') {
						this.$store.commit('xxy/setPay', false)
					}
					if(res.returnCode == 2) {
						// Toast({
						// 	message: res.msg,
						// 	duration: 2000,
						// 	type: 'fail'
						// });
						return
					}
					this.pageNum = 1;
					this.data = [];
					this.getNum();
				}
			
			},

			//
			async confirm(val) {
				let res = await confirmOrder(val);
				if(res.returnCode == '0') {
					Toast({
						message: res.errmsg,
						duration: 2000,
						type: 'fail'
					});
					return;
				}
				if(res.returnCode == '1' || res.returnCode == 1) {
					Toast({
						message: '确认收货成功！',
						duration: 2000,
						type: 'success'
					});
					this.$store.dispatch('cjy/changeClassifyIndex', 4);
				}

			},
			async confirmPay(orderNo, parentOrderNo, orderType) {
				let res = await confirmPayment(parentOrderNo);
				if(res.returnCode == '0') {
					Toast({
						message: res.msg,
						duration: 2000,
						type: 'fail'
					});
					return;
				} else {
					// this.$router.push('pay/' + parentOrderNo);
					this.$router.push({name: "pay", params:{orderNo: parentOrderNo, orderType,IsOrderPage:true}});
				}
			},
			img(param) {
				let arr = [];
				param.forEach((key, value) =>
					arr.push(key.goodsImg)
				);
				return arr
			},
			add(val) {
				let j = 0;
				for(let i of val) {
					if(i.goodsUnit == "kg") {
						j++;
					} else {
						j += i.goodsNum;
					}

				}
				return j;
			},
			goEvaluate(item) {
				console.log(item[0].orderNo,'abcdeeefffff')
				// 过滤退款不能评价的商品
				let itemDetail = item && item.filter(function(val) {
					if (val.estimateStatus != 2) {
						return true;
					} 
					return false
				})
				// 过滤需要传参到评价页面的参数
				let itemQuery = itemDetail && itemDetail.map((son) => {
					return {
						"orderNo": son.orderNo,
						"goodsId": son.goodsId,
						"goodsCode": son.goodsCode,
						"goodsName": son.goodsName,
						'buyType': son.buyType,
						"goodsImg": son.goodsImg,
						'goodsSpec': son.goodsSpec,
						'realPrice':son.realPrice,
						'goodsUnit':son.goodsUnit
					}
				})
				console.log(itemQuery,'itemQuery')
				this.$store.commit('lyj/SET_ITEMQUERY',itemQuery)
				this.$router.push({
					path: 'evaluate',
					query:{"orderNo": item[0].orderNo,}
				});		
				
			},
			tangshiStatus(item) {
				const allFoodNumber = item.orderDetails.length
				if (item.payStatus === 0 && item.status === 0) {
					return "待付款"
				}
				if (item.payStatus === 0 && item.status === 1) {
					return "已取消"
				}
				if (item.status === 2) {
					return "已关闭"
				}
				if (item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum > 0) {
					return "待取餐("+item.eatingStatusNumber.waitingNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum > 0){
					return "制作中（"+item.eatingStatusNumber.producingNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum == 0 &&item.eatingStatusNumber.completedNum >0){
					return "已取餐("+item.eatingStatusNumber.completedNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum == 0 &&item.eatingStatusNumber.completedNum ==0){
					return "已关闭"
				}
			},
			offlineStatus(item) {
				console.log(item,"你好啊线下堂食")
				const allFoodNumber = item.orderDetails.length
				if (item.payStatus === 0 && item.status === 0) {
					return "待付款"
				}
				if (item.payStatus === 0 && item.status === 1) {
					return "已取消"
				}
				if (item.status === 2) {
					return "已关闭"
				}
				if (item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum > 0) {
					return "待取餐("+item.eatingStatusNumber.waitingNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum > 0){
					return "制作中（"+item.eatingStatusNumber.producingNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum == 0 &&item.eatingStatusNumber.completedNum >0){
					return "已取餐("+item.eatingStatusNumber.completedNum+")"
				}else if(item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum == 0 && item.eatingStatusNumber.producingNum == 0 &&item.eatingStatusNumber.completedNum ==0){
					return "已关闭"
				}

				// // 全部制作中
				// if (item.eatingStatusNumber&&item.eatingStatusNumber.producingNum == allFoodNumber) {
				// 	return "制作中("+item.eatingStatusNumber.producingNum+")"
				// }
				// // 全部已取餐
				// if (item.eatingStatusNumber&&item.eatingStatusNumber.completedNum == allFoodNumber) {
				// 	return "已取餐("+allFoodNumber+")"
				// }
				// // 有待取餐的
				// if (item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum > 0) {
				// 	return "待取餐("+item.eatingStatusNumber.waitingNum+")"
				// }
				
				// // 没有待取餐，但是有制作中的
				// if (item.eatingStatusNumber&&item.eatingStatusNumber.waitingNum === 0 && item.eatingStatusNumber.producingNum > 0){
				// 	return "制作中（"+item.eatingStatusNumber.producingNum+")"
				// }
			},
			orderTypeStatus(item) {
				let state;
				if(item.scanOrder && item.scanOrder === 1 && item.payStatus === 2) {
					state = '已完成';
				} else if(item.orderType && (item.orderType === 1 || item.orderType === 5 || item.orderType === 6)  && item.payStatus === 2) {
					state = '已完成';
				} else if(item.status === 1) {
					state = '已取消';
				} else if(item.status === 2) {
					state = '交易关闭';
				}
				// else if (item.status === 3) {
				//   state = '已退款';
				// } else if (item.status === 5) {
				//   state = '退货退款';
				// }
				else if(item.payStatus === 0) {
					state = '待付款';
				} else if(item.logisticsStatus === 0) {
					state = '待配送';
				} else if(item.logisticsStatus === 1) {
					state = '配送中';
				} else if(item.logisticsStatus === 2 && !item.estimateFlag && item.orderType != 2) {
					state = '待评价';
				} else if((item.logisticsStatus === 2 && item.estimateFlag == true) || (item.logisticsStatus === 2 && item.orderType == 2)) {
					state = '已完成';
				}
//				console.log("item.status===",item.status,"item.payStatus===",item.payStatus,"state====",state)
				return state;
			},
			orderTypeStatusing(item) {
				let state;
				if(item.scanOrder && item.scanOrder === 1 && item.payStatus === 2) {
					state = '已完成';
				} else if(item.orderType && (item.orderType === 1 || item.orderType === 5 || item.orderType === 6)  && item.payStatus === 2) {
					state = '已完成';
				} else if(item.status === 1) {
					state = '已取消';
				} else if(item.status === 2) {
					state = '交易关闭';
				}
				// else if (item.status === 3) {
				//   state = '已退款';
				// } else if (item.status === 5) {
				//   state = '退货退款';
				// }
				else if(item.payStatus === 0) {
					state = '待付款';
				} else if(item.logisticsStatus === 0) {
					state = '待配送';
				} else if(item.logisticsStatus === 1) {
					state = '配送中';
				} else if(item.logisticsStatus === 2 && !item.estimateFlag && item.orderType != 2) {
					state = '待评价';
				} else if((item.logisticsStatus === 2 && item.estimateFlag == true) || (item.logisticsStatus === 2 && item.orderType == 2)) {
					state = '已完成';
				}
				console.log("item.status===",item.status,"item.payStatus===",item.payStatus,"state====",state)
				return state;
			},
			orderTypes(item) {//88纯线下   99 线上到线下
				let reg = /^88\d{16}$/;
				return reg.test(item)
			},
			sonPrice(item, son) {
				// if(item.scanOrder == 1)return
				let a = son.goodsUnit == 'kg' ? Number(son.goodsPrice / 2).toFixed(2) : Number(son.totalMoney / son.outGoodsNum).toFixed(2);
				return a;
			},
			realPrice(item, detail) {
				// if(item.scanOrder == 1)return
				let a = detail.goodsUnit == 'kg' ? Number(detail.realPrice / 2).toFixed(2) : Number(detail.realTotalMoney / detail.outGoodsNum).toFixed(2);
				return a;
			},
			turnPage(data, type) {
				if(type === 1) {
					let url = data.orderType != 1 ? {
						path: 'orderDetails',
						query: {
							shopId: data.parentOrderNo,
							orderStatus: this.number
						}
					} : '';
					this.$router.push(url);
				}
			},
			getBillStatus(){
				//获取发票使用状态
                var sessionId = localStorage.getItem('sessionId');
                var config = {
                   url : window.api.base_host+'/baseConfig/findByCode',
                //    data:JSON.stringify(datas),
                   method:"GET",
                   headers: {'sessionId': sessionId, 'Content-Type':'application/json', 'Accept' : 'application/json'},
                }
                axios(config).then((res) => {
                      try{
                        if(res.data.returnCode === 1){
							this.setInvoiceFlag(res.data.data[0].invoiceFlag)

                        }else {
                            
                        }

                      }catch(err){

                      }
                   
                })
			},
			getworkingInfo(val) {
				if(val instanceof Array) {
					return val[0].processingItem
				} else {
					return val.processingattribute
				}
			}
		},
		filters: {
			//转换时间格式
			getTime: function(param) {
				let date = new Date(param);
				let year = date.getFullYear();
				let month = checkTime(date.getMonth() + 1);
				let day = checkTime(date.getDate());
				let hour = checkTime(date.getHours());
				let min = checkTime(date.getMinutes());
				let sec = checkTime(date.getSeconds());

				function checkTime(i) {
					if(i < 10) {
						i = '0' + i;
					}
					return i;
				}

				return year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec;
			}

		},
		
	}
</script>

<style scoped>
.customHeaderStyle{
		position: relative;
		background: #fff;
		min-height: 3rem;
		border-bottom: 1px solid #eaeaea;
		color: #444;
		font-weight: 700;
		left: 0;
		top: 0;
		line-height: 2.25rem;
		/* z-index: 2; */
		width: 100%;
		font-size: .9rem;
		text-align: center;
		margin: 0;
		padding: 0;
	}
	.headerCustomTitle{
		overflow: hidden;
		right: 6rem;
		font-weight: 500;
		min-height: 2.25rem;
		position: absolute;
		margin: 0;
		text-align: left;
		white-space: nowrap;
		left: 3rem;
		width: auto;
		text-overflow: ellipsis;
		z-index: 2;
		font-size: 1.1rem;
		margin-top: .35rem;
		top: 1px;
	}
	.order_list_div {
		background: #fff;
		position: relative;
		overflow: hidden;
		width: 100%;
		top: 0rem;
		height: 100%;
		overflow-y: scroll;
	}
	
	#aLink {
		color: #0f8de0;
		text-decoration: underline;
		float: left;
	}
	
	.subtotal_list .aui-list-item-media {
		width: 6rem;
		height: 6rem;
	}
	
	.no_data {
		background: #fff;
	}
	
	.no_data img {
		width: 70%;
		height: auto;
		background: #fff;
	}
	
	.centent {
		background: rgba(215, 206, 206, 0.5);
	}
	
	.edit_address {
		border-bottom: none !important;
	}
	
	.subtotal_list .aui-list-item-media {
		width: 4rem;
		height: 4rem;
	}
	
	#scrollOuter {
		overflow-y: scroll !important;
	}
	
	.aui-list .aui-list-item-right {
		max-width: 100% !important;
		margin-left: 0
	}
	
	.aui-list .aui-list-item-right span {
		white-space: nowrap
	}
	
	.subtotal span {
		color: #333;
		font-weight: normal;
		display: block;
		width: 90px;
	}
	.aui-list .aui-list-item-inner.suggest {
		/* width: auto; */
		max-width: 60%;
	}
	.subtotal {
		position: absolute;
    	right: 0;
	}
	.subtotal p {
		white-space: nowrap
	}
	
	.img_span {
		position: absolute;
		width: 2rem;
		background: #faa73c;
		color: #fff;
		border-bottom-right-radius: 7px;
		z-index: 9999;
		font-size: 0.5rem;
	}
	
	.img_span_1 {
		background: #eb3838;
	}
	
	.hasEvaluate {
		text-align: right;
		padding: 0.3rem 0.75rem;
	}
	
	.hasEvaluate .hasEvaluate_btn {
		color: #ccc
	}
	
	.aui-btn-outlined .pfo-fn {
		margin-top: 0
	}
</style>